package wfl.spec.edu;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

public class MessageAdapter extends ArrayAdapter<Message>{
    private int itemLayoutId;
    public MessageAdapter(Context context, int textViewResourceId, List<Message> objects) {
        super(context, textViewResourceId, objects);
        itemLayoutId = textViewResourceId;
    }
    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        Message f = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(itemLayoutId, parent, false);
        MyImageView iv = (MyImageView)view.findViewById(R.id.image);
        TextView name = (TextView)view.findViewById(R.id.title);
        iv.setImageURL("http://www.yyjsx.xyz" + f.getPreview());
        name.setText(f.getTitle());
        return view;
    }
}
